<template>
  <swiper :autoplay="swiper_option.autoplay" :loop="swiper_option.loop" :speed="swiper_option.speed"
    :pagination="swiper_option.pagination">
    <swiper-slide v-for="item in bannerList" :key=item.id>
      <img :src="item.imgUrl" :alt="item.id">
    </swiper-slide>
  </swiper>
</template>

<script>
  import { reactive, onMounted } from 'vue'
  import { useHomeStore } from "../../../store/home"  //引入home仓库
  import { storeToRefs } from 'pinia'  //引入方法让仓库里的值可以解构赋值并且具有响应式
  import { Swiper, SwiperSlide } from 'swiper/vue/swiper-vue.js';
  import SwiperCore, { Autoplay, Pagination } from "swiper"
  import 'swiper/swiper.min.css';
  // import 'swiper/modules/effect-fade/effect-fade.min.css'  //引入轮播样式-淡入淡出的css样式
  SwiperCore.use([Autoplay, Pagination])

  export default {
    name: "Carousel",
    components: {
      Swiper,
      SwiperSlide,
    },
    setup() {
      const store = useHomeStore()
      let swiper_option = reactive({
        autoplay: {
          delay: 3000,
          disableOnInteraction: false
        },
        loop: true,
        speed: 1000,
        liner: true,
        pagination: {
          clickable: true,
        }
      })

      onMounted(() => {
        store.getBannerList()
      })
      let { bannerList } = storeToRefs(store) //从仓库获取数据
      return {
        bannerList,
        swiper_option
      }
    }
  };
</script>

<style lang="css" scoped>
  .swiper-wrapper {
    width: 100%;
  }

  .swiper-wrapper img {
    width: 100%;
    height: 100%;
  }
</style>